$infile = $ARGV[0];
chomp($infile);
$outfile = $ARGV[1];
chomp($outfile);
open(BUFF,"$infile");
open(WRBUFF,">$outfile");
@dir = split(/\//,$infile);
pop(@dir);
$dir = join('/',@dir);
system("mkdir $dir/temp");
while($line = <BUFF>)
{
	chomp($line);
	@array = split(/\t/,$line);
	system("cp /data1/bsi/BORA_processing/devel/data_HGUPLUS2/GSE2109_RAW/$array[0].gz /data1/bsi/BORA_processing/devel/data_HGUPLUS2/temp/");
	system("Rscript /data1/bsi/BORA_processing/devel/data_HGUPLUS2/frmascript.R");
	open(BU1,"/data1/bsi/BORA_processing/devel/data_HGUPLUS2/temp/afternormalization");
	open(BU2,"/data1/bsi/BORA_processing/devel/data_HGUPLUS2/temp/beforenormalization");
	$k =0;
	$sum = 0;
	while($lin1 = <BU1>)
	{
		chomp($lin1);
		$lin2 = <BU2>;
		chomp($lin2);
		$arr[$k]= $lin1-$lin2;	
		$k++;
		$sum = $sum+$array[$k];
	}
	$avg = $sum/$k;
	$sum1 = 0;
	for($i=0;$i<@arr;$i++)
	{
		$sum1 = $sum1 + abs($arr[$i] - $avg);
	}
	$avg1 = $sum1/$k;
	print WRBUFF $array[0]."\t".$avg1."\n"; 
	system("rm -rf $dir/temp/*");
}
